import React, { Component } from 'react';
import { connect } from 'react-redux';
import E from "wangeditor";
import {  Form, } from "antd";
import action from "../../../store/action";
class index extends React.Component {
    constructor() {
        super();
        this.state = {
            editorContent:''
        }
    }
   async componentDidMount() {
        const elem = this.refs.editorElem;
        const editor = new E(elem);
        // editor.customConfig.uploadImgServer = '/DOMAIN_API';
        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
        editor.customConfig.uploadImgShowBase64 = false;
        editor.customConfig.uploadFileName = 'article'  //上传参数 自定义
        // 使用 onchange 函数监听内容的变化，并实时更新到 state 中
        editor.customConfig.uploadImgServer = 'http://www.bestzc.cn:8080/materials.web/';
        editor.customConfig.uploadImgHooks = {
            customInsert: function (insertImg, result, editor) {
                var url = result.data.url  //监听图片上传成功更新页面
                insertImg(url)
            }
        };
        editor.customConfig.onchange = html => {
            this.setState({
                editorContent: html
            })
           
            const {dynamic_wang}=this.props;
            dynamic_wang(html)
        }
        editor.create();
    }
    render() {    
        return <div ref="editorElem" className='add_art' >
        </div>
    }
}

export default connect(state=>({...state.custom}),action.custom)(index);
